<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <!-- <cpn v-bind:cmovies="movies" v-bind:cmessage="message"></cpn> -->

        <!-- 简化写法 -->
        <cpn :cmovies="movies" :cmessage="message"></cpn>
    </div>

    <template id="cpn">
        <div>
            <p>{{cmovies}}</p>
            <h2>{{cmessage}}</h2>

            <ul>
                <li v-for="item in cmovies" :Key="item">{{item}}</li>
            </ul>
        </div>
    </template>

    <script src="../js/vue.js"></script>
    <script>
        // 父组件传子组件: props
        const cpn = {
            template: '#cpn',
            // props: ['cmovies','cmessage'] 数组写法
            props: { //对象写法,优势在于可以指定其类型,即做类型限制,并可提供默认值
            //类型限制
                // cmovies: Array,
                // cmessage: String,
            //类型限制并提供一些默认值
                cmessage: {
                    type: String, //类型必须为String
                    default: '草鸡大学',
                    required: true //在使用该组件时,是否必须传入该值,如果为true但没有传入,则会报错
                },
                //类型是对象或者数组时,默认值必须是一个函数
                cmovies: {
                    type: Array,
                    default(){
                        return []
                    }
                }
            }
        }

        const app = new Vue({
            el: '#app',
            data: {
                movies: ['海王','海贼王','海尔兄弟'],
                message: '苏州大学'
            },
            components: {
                cpn
            }
        })
    </script>
</body>
</html>